package com.jayson.server.catalina;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 虚拟主机类
 * 保存网络地址、项目文件路径和项目上下文
 */
public class Host {

    private String name;

    private String appBase;

    private List<Context> contexts;

    public Host() {
    }

    public Host(String name, String appBase) {
        this.name = name;
        this.appBase = appBase;
        this.contexts  = new ArrayList<>();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAppBase() {
        return appBase;
    }

    public void setAppBase(String appBase) {
        this.appBase = appBase;
    }

    public List<Context> getContexts() {
        return contexts;
    }

    public void setContexts(List<Context> contexts) {
        this.contexts = contexts;
    }

    /**
     * 根据文件路径去读取应用上下文
     */
    public void init(){
        File rootFile = new File(appBase);
        if(rootFile.isFile()){
            throw new RuntimeException("======>>>>>>文件路径错误");
        }
        File[] files = rootFile.listFiles();
        for (File file : files) {
            Context context = new Context();
            context.init(file);
            contexts.add(context);
        }
    }
}
